package com.leetcode;

import java.util.HashSet;

public class _128_LongestConsecutive {
    public int longestConsecutive(int[] nums) {
        HashSet<Integer> numsSet = new HashSet<>();
        for (int num : nums) {
            numsSet.add(num);
        }
        int result = 0;
        for (int num : numsSet) {
            if(!numsSet.contains(num - 1)) {
                int currNum = num;
                int curlen = 1;
                while(numsSet.contains(currNum + 1)) {
                    currNum++;
                    curlen++;
                }

                result = Math.max(result, curlen);
            }
        }
        return result;
    }
}
